home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CPrefsFile & Friends 1.0 / CPrefsFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.8 KB  |  95 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CPrefsFile.h
  3.  * Version 1.1, 13 April 1992
  4.  *
  5.  * © Copyright 1992 by James R. McCarthy.  All rights reserved.
  6.  * This code can be both distributed and used freely.
  7.  *
  8.  */
  9.  
  10.  
  11.  
  12. /******************************/
  13.  
  14. #pragma once
  15.  
  16. /******************************/
  17.  
  18. #include <CResFile.h>
  19.  
  20. /******************************/
  21.  
  22.  
  23.  
  24. class CPrefsFile : public CResFile {
  25.     
  26. public:
  27.     
  28.     void            IPrefsFile(short strsID, OSType fileType,
  29.                         Boolean lookInApplFolderAlso);
  30.     void            Dispose(void);
  31.     
  32.     
  33.         /****    Methods which your subclass may override, if desired. ****/
  34.     
  35.     Boolean        getPrefsCanBeWritten(void);        // Can the prefs be written?
  36.     
  37. protected:
  38.     
  39.     OSType        getRsrcType(void);                    // The resource type
  40.     short            getRsrcID(void);                        // The resource ID
  41.     void            getRsrcName(Str63 theName);        // The resource name
  42.     Boolean        areTheCurrentPrefsAcceptable(void);        // Verify they're OK
  43.     
  44.     
  45.         /****    Methods which your subclass MUST override. ****/
  46.     
  47.     void            assignToPrefsHndl(Handle theHandle);
  48.     Handle        valueOfPrefsHndl(void);
  49.     short            sizeOfPrefs(void);
  50.     
  51.     
  52.         /****    Methods which your subclass normally won't have to override. ****/
  53.     
  54.         /* Low-level convenience methods. */
  55.     Boolean        getIndPrefsString(unsigned char *theString, short index);
  56.     void            displayAlert(short firstIndex, short secondIndex);
  57.     void            forgetStrListResource(void);
  58.     void            findName(void);
  59.     void            findFolder(Boolean lookInApplFolderAlso);
  60.         /* Methods that mess with the file and/or determine its status. */
  61.     void            tryToCreateNew(void);
  62.     void            tryToOpen(void);
  63.     void            tryToWrite(void);
  64.         /* Preference-manipulating methods. */
  65.     void            forgetPrefsHndl(void);
  66.     Handle        getPrefsHndl(void);
  67.     void            addPrefsHndl(Handle theHndl);
  68.         /* Method to handle an error with the prefs file. */
  69.     void            displayCannotWritePrefsAlert(OSErr theError);
  70.         /* Methods to check acceptability and handle invalid prefs. */
  71.     void            displayInvalidPrefsAlert(void);
  72.     void            displayInvalidDefaultPrefsAlert(void);
  73.     void            checkPrefsForAcceptability(void);
  74.         /* High-level methods. */
  75.     void            readPrefs(void);
  76.     void            writePrefs(void);
  77.     void            readDefaultPrefs(void);
  78.     
  79.     
  80.         /****    Class variables. ****/
  81.     
  82.     Str31            itsApplName;    // Name of the application
  83.     short            itsApplRefNum;    // Reference number for application's resource fork
  84.     short            itsProjRsrcRefNum;    // If run from ThC, refNum for .π.rsrc file
  85.     short            itsStrsID;        // 'STR#' rsrc to search for the "Prefs" appendads
  86.     OSType        itsFileType;    // Type of prefs file
  87.     OSType        itsRsrcType;    // Resource type to use to store data in prefs file
  88.     short            itsRsrcID;        // Resource ID to use
  89.     Str63            itsRsrcName;    // Name to give the resource
  90.     short            itsPermissionType;        // Permission with which to open the file
  91.     Boolean        itsPrefsCouldBeWritten;    // Did IPrefsFile succeed in writing?
  92.     Boolean        isReadingDefaultPrefs;    // Are we in the middle of reading defaults?
  93.     
  94. } ;
  95.